home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 1122 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.7 KB

  1. From: jason@cygnus.com (Jason Merrill)
  2. Message-ID: <u93f63214o.fsf@yorick.cygnus.com>
  3. X-Original-Date: 16 Apr 1996 16:35:35 -0700
  4. Path: in2.uu.net!bounce-back
  5. Date: 17 Apr 96 08:49:00 GMT
  6. Approved: fjh@cs.mu.oz.au
  7. Newsgroups: comp.std.c++
  8. Subject: Re: Just one more library function
  9. Organization: Cygnus Support, Mountain View, CA
  10. References: <Pine.HPP.3.91.960416133333.19297A-100000@hadron.fi.uib.no>
  11. In-Reply-To: Igor Boukanov's message of 16 Apr 1996 13:15:25 PDT
  12. X-Newsreader: Gnus v5.0
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBFAgUBMXSwluEDnX0m9pzZAQFSKAF/eQj/ntLuT9R9kmR4uCjP/mXtfa436RiL
  15.     YXZXPBecWeVlQxAINDOw9LWD9RAmezkq
  16.     =qZG4
  17.  
  18. >>>>> Igor Boukanov <Igor.Boukanov@fi.uib.no> writes:
  19.  
  20. > Why do not require that every C++ implementation should provide function
  21. > that will return for the pointer obtained from new[] the number of 
  22. > allocated elements, i.e. something like:
  23.  
  24. > template<class T> size_t array_allocation_size(T* p);
  25.  
  26. > So for 'int* p = new int[3];' 'array_allocation_size(p)' will return 3.
  27.  
  28. > Such function will be very easy to implement because in the case of
  29. > delete[] compiler use something like this.
  30.  
  31. Not necessarily.  For instance, g++ only stores the number of elements if 
  32.  
  33. 1) The element type has a destructor, or
  34. 2) The element type has an operator delete that takes the size_t argument.
  35.  
  36. Jason
  37. ---
  38. [ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
  39. [ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
  40. [ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
  41. [ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
  42. [ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]
  43.